<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{$Think.lang.eidtcontent}</title>
    <link rel="stylesheet" href="/static/admin/vendor/layui/css/layui.css">
    <link rel="stylesheet" href="/static/admin/custom/css/style.css">
    <style>
        .layui-form-select dl{z-index: 2;}
        #thumb_list{padding-top: 8px;}
        #thumb_list img{border: 1px solid #DDD;padding: 3px;border-radius: 5px;}
        #thumb_list span{position: relative;display: inline-block;margin-right: 5px;}
        #thumb_list span .delimg{position: absolute;right:3px;top:3px;}
    </style>
</head>
<body style="padding:10px 10px;margin-bottom: 50px;">
<div class="layui-container">
    <form class="layui-form" action="?" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">{$Think.lang.depID}</label>
            <div class="layui-input-inline">
                <select name="cid" required lay-verify="required" lay-filter="lanmu">
                    <option value="">{$Think.lang.selectdepID}</option>
                    {volist name="cate" id="vo"}
                    <option value="{$vo.id}" data="{$vo.typeid}" {eq name="vo.id" value="$article.cid"}selected{/eq}>{$vo.name}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{$Think.lang.title}</label>
            <div class="layui-input-block">
                <input type="text" name="title" value="{$article.title}" required  lay-verify="required" placeholder="{$Think.lang.titletip}" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{$Think.lang.keyword}</label>
            <div class="layui-input-block">
                <input type="text" name="keyword" value="{$article.keyword}" placeholder="{$Think.lang.keywordtip}" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{$Think.lang.desc}</label>
            <div class="layui-input-block">
                <textarea name="desc" placeholder="{$Think.lang.desctip}" class="layui-textarea">{$article.desc}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{$Think.lang.remark}</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="{$Think.lang.remarktip}" class="layui-textarea">{$article.remark}</textarea>
            </div>
        </div>

        <div class="layui-form-item" id="model" {neq name="article.type" value="3"}style="display: none;"{/neq}>
            <label class="layui-form-label">{$Think.lang.model}</label>
            <div class="layui-input-block">
                <input type="text" name="model" value="{$article.model}" placeholder="{$Think.lang.modeltip}" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div id="team" {neq name="article.type" value="6"}style="display: none;"{/neq}>
            <div class="layui-form-item">
                <label class="layui-form-label">{$Think.lang.job}</label>
                <div class="layui-input-inline">
                    <input type="text" name="zhiwu" value="{$article.zhiwu}" placeholder="{$Think.lang.jobtip}" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">{$Think.lang.positional}</label>
                <div class="layui-input-inline">
                    <input type="text" name="zhicheng" value="{$article.zhicheng}" placeholder="{$Think.lang.positionaltip}" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{$Think.lang.author}</label>
            <div class="layui-input-inline">
                <input type="text" name="author" value="{$article.author}" placeholder="{$Think.lang.authortip}" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{$Think.lang.views}</label>
            <div class="layui-input-inline">
                <input type="text" name="views" value="{$article.views}" required  lay-verify="required" placeholder="{$Think.lang.viewstip}" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{$Think.lang.addtime}</label>
            <div class="layui-input-inline">
                <input type="text" name="addtime" value="{$article.addtime|date='Y/m/d H:i:s',###}" required  lay-verify="required" placeholder="{$Think.lang.addtimetip}" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{$Think.lang.top}</label>
            <div class="layui-input-inline">
                <input type="checkbox" name="istop" lay-skin="switch" {$article.istop?"checked":""} lay-text="{$Think.lang.toptip}" value="1">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{$Think.lang.thum}</label>
            <div class="layui-input-block">
                <input type="hidden" name="pic"  placeholder="{$Think.lang.thumtip}" autocomplete="off" class="layui-input">
                <button type="button" class="layui-btn" id="uploadimg">
                    <i class="layui-icon">&#xe67c;</i>{$Think.lang.thumtip}
                </button>
                <div id="thumb_list">
                    {volist name="article.pic" id="vo"}
                    {if condition="$vo neq ''"}
                    <span>
                        <img src="/{$vo}" alt="" height="80">
                        <button type="button" class="layui-btn layui-btn-danger layui-btn-mini delimg" onclick="delimg(this);" data="{$vo}">
                        <i class="layui-icon">&#xe640;</i>
                        </button>
                    </span>
                    {/if}
                    {/volist}
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{$Think.lang.contenttitle}</label>
            <div class="layui-input-block">
                <textarea id="content" name="content" type="text/plain" style="height:300px;">{$article.content}</textarea>
            </div>
        </div>
        <input type="hidden" name="__token__" value="{$Request.token}" />
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">{$Think.lang.editbtn}</button>
            </div>
        </div>
    </form>
</div>
<script src="/static/admin/vendor/js/jquery.js"></script>
<script src="/static/admin/vendor/layui/layui.js"></script>
<!-- 配置文件 -->
<script type="text/javascript" src="/static/admin/vendor/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/static/admin/vendor/ueditor/ueditor.all.js"></script>
<script src="/static/admin/custom/js/admin.js"></script>
<script>
    var ue = UE.getEditor('content');
    layui.use(['form','upload'], function(){
        var form = layui.form;
        var upload = layui.upload;
        //监听提交
        form.on('submit(formDemo)', function(data){
        });
        //监听栏目
        form.on('select(lanmu)', function(data){
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            var lmtype=$(data.elem).find('option:selected').attr('data');
            switch (lmtype){
                case "6":
                    $('#team').fadeIn();
                    $('#model').hide();
                    break;
                case "3":
                    $('#model').fadeIn();
                    $('#team').hide();
                    break;
                default :
                    $('#model').hide();
                    $('#team').hide();
                    break;
            }
        });
        //创建一个上传组件
        upload.render({
            elem: '#uploadimg'
            ,url: '{:url("common/uploadimg")}'
            ,accept: 'images' //允许上传的文件类型
            ,field:"imgfile"
            ,size: 2048 //最大允许上传的文件大小
            ,done: function(res, index, upload){ //上传后的回调
                layer.close(layer.index,{isOutAnim:true});
                setTimeout(function () {
                    layer.msg(res.msg);
                    if(res.code==1){
                        var pic=$('input[name=pic]').val();
                        if(pic==""){
                            $('input[name=pic]').val(res.img);
                        }else{
                            $('input[name=pic]').val(pic+","+res.img);
                        }
                        var str;
                        str="<span>";
                        str=str+'<img src="/'+res.img+'" alt="" height="80">';
                        str=str+'<button type="button" class="layui-btn layui-btn-danger layui-btn-mini delimg" onclick="delimg(this);" data="'+res.img+'">';
                        str=str+'<i class="layui-icon">&#xe640;</i>';
                        str=str+'</button>';
                        str=str+'</span>';
                        $('#thumb_list').append(str);
                    }else{

                    }

                },500);
            }
            ,before:function () {
                var index = layer.load();
            }

            //,……
        })
    });
    $(function(){
        $(window.parent.document).find('#righttitle').text($('title').text());
    });
    //删除内容缩略图片
    function delimg(obj) {
        var picurl=$(obj).attr('data');
        $.ajax({
            type:"post",
            url:"{:url('common/delimg')}",
            data:{'url':picurl},
            success:function (res) {
                var picvalue=$('input[name=pic]').val();
                var str="";
                if(res.code==1 || res.code==2){
                    //栏目图片文本框中图片地址处理
                    if(picvalue==picurl){
                        $('input[name=pic]').val('');
                    }else{
                        str=picvalue.replace(picurl+",","");
                        str=str.replace(","+picurl,"");
                        $('input[name=pic]').val(str);
                    }
                    //删除/移除缩略图
                    $(obj).parent().remove();
                    layer.msg(res.msg);
                }
                if(res.code==0){
                    layer.msg(res.msg);
                }
            }
        });
    }
</script>
</body>
</html>